// pages/navigation/old/credit/credit.js
const app = getApp()
const select = {
  '学年': ['大一', '大二', '大三', '大四'],
  '学期': ['上', '下']
};

Page({

  /**
   * 页面的初始数据
   */
  data: {
    columns: [{
      values: select['学年'],
      defaultIndex: 0
    },
    {
      values: select['学期'],
      defaultIndex: 0
    }
    ],
    year: '大一',
    term: '上',
    creditList: []
  },
   /**
   * 发起查询
   */
  onConfirm(e) {
    wx.showLoading({
      title: '正在查询',
    })
    var time = this.data.year+this.data.term;
    wx.cloud.database().collection('score_info')
    .where({semester:time})
    .get()
    .then(res => {
      console.log('查找该学期学分成功',res.data);
      var list = res.data;
      for(var i = 0; i <list.length; i ++){
        list[i].credit = list[i].credit.toFixed(1);
      }
      this.setData({
        creditList:list
      })
      wx.hideLoading();
    })
    .catch(err => {
      console.log('查找该学期学分失败',err);
    })
  },
  onChange:function(e){
    this.setData({
      year:e.detail.value[0],
      term:e.detail.value[1]
    })
  },
  onLoad: function (options) {

  }
})